package jp.tuyano.helo.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;

public class Delete implements EntryPoint {
    private Label label;
    private TextBox id;

    private final DeletePDServiceAsync deleteService = GWT.create(DeletePDService.class);

    private static final String SERVER_ERROR = "SERVER ERROR!!";

    
    public void onModuleLoad() {
        label = new Label("please type ID...");
        RootPanel.get("delete_label").add(label);
        HorizontalPanel panel = new HorizontalPanel();
        panel.add(new Label("Delete ID:"));
        id = new TextBox();
        panel.add(id);
        Button button = new Button("Delete");
        button.addClickHandler(new ClickHandler(){
            
            public void onClick(ClickEvent event) {
                deleteService.deleteEntity(new Long(id.getText().toString()),
                        new AsyncCallback<String>(){
                    
                    public void onFailure(Throwable caught) {
                        label.setText(SERVER_ERROR);
                    }
                    
                    public void onSuccess(String result) {
                        label.setText(result);
                    }
                    
                });
            }
        });
        panel.add(button);
        RootPanel.get("delete_panel").add(panel);
    }

}
